/**
 * 
 */
package com.skood.security.service.impl;

import java.util.List;

import org.springframework.util.StringUtils;

import com.skood.core.ExecuteResult;
import com.skood.security.dao.UserDAO;
import com.skood.security.domain.User;
import com.skood.security.service.UserService;

/**
 * @author keege
 * @date 2013-9-9
 * 用户管理
 */
public class UserServiceImpl implements UserService{

	private UserDAO userDAO;
	@Override
	public List<User> searchUsers() {
		// TODO Auto-generated method stub
		return userDAO.searchUsers();
	}
	
	@Override
	public ExecuteResult<User> login(String username, String password) {

		ExecuteResult<User> executeResult = new ExecuteResult<User>();
		username = StringUtils.trimWhitespace(username);
		password = StringUtils.trimWhitespace(password);
		if(StringUtils.isEmpty(username)||StringUtils.isEmpty(password)){
			//用户名或密码不能为空
		}
		User user = userDAO.getUserByName(username);
		if(user == null){
			//用户不存在
			return executeResult;
		}
		if(!password.equals(user.getPassword())){
			//用户密码错误
			return executeResult;
		}
		executeResult.setResult(user);
		executeResult.setSuccess(true);
		return executeResult;
	}



	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

	
}
